if(typeof String.prototype.trim == 'undefined'){
    String.prototype.trim = function(){
        return this.replace(/^\s+/, "").replace(/\s+$/, "");
    }
};

if(typeof String.prototype.addslashes == 'undefined') {
    String.prototype.addslashes = function (boxquotechar) {
        if (typeof boxquotechar == 'undefined' || !boxquotechar)
            boxquotechar = '';
        var str = this;
        if (boxquotechar == '"' || boxquotechar == 2) str = str.replace(/"/g, '\\"');
        else {
            if (boxquotechar == '\'' || boxquotechar == 1) str = str.replace(/'/g, '\\\'');
            else if (boxquotechar == '' || boxquotechar == '"\'' || boxquotechar == '\'"' || boxquotechar == 'both' || boxquotechar == 'all' || boxquotechar == 3) {
                str = str.replace(/'/g, '\\\'').replace(/"/g, '\\"');
            }
        }
        return str.replace(/\\/g, '\\\\').replace(/\u0008/g, '\\b').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\f/g, '\\f').replace(/\r/g, '\\r');
    }
};
if(typeof String.prototype.reverse == 'undefined') {
    String.prototype.reverse = function () {
        var n = this.length;
        var a = this.split('');
        for (var i = 0; i < n >> 1; i++) {
            var temp = a[i];
            a[i] = a[n - 1 - i];
            a[n - 1 - i] = temp;
        }
        return a.join('')
    }
};
if(typeof ArrayEquals == 'undefined') {
// Warn if overriding existing method
//if(Array.prototype.equals)   console.warn("Overriding existing Array.prototype.equals. Possible causes: New API defines the method, there's a framework conflict or you've got double inclusions in your code.");
// attach the .equals method to Array's prototype to call it on any array
    function ArrayEquals (me,array) {
        // if the other array is a falsy value, return
        if (!array) return false;
        // compare lengths - can save a lot of time
        if (me.length != array.length) return false;
        for (var i = 0, l = me.length; i < l; i++) {
            // Check if we have nested arrays
            if (me[i] instanceof Array && array[i] instanceof Array) {
                // recurse into the nested arrays
                if (!me[i].equals(array[i]))
                    return false;
            } else if (me[i] != array[i]) {
                // Warning - two different object instances will never be equal: {x:20} != {x:20}
                return false;
            }
        }
        return true;
    }
}
if(typeof ObjectEquals == 'undefined') {
     function ObjectEquals(me,object2) {
        //For the first loop, we only check for types
        for (propName in me) {
            //Check for inherited methods and properties - like .equals itself
            //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
            //Return false if the return value is different
            if (me.hasOwnProperty(propName) != object2.hasOwnProperty(propName)) {
                return false;
            }
            //Check instance type
            else if (typeof me[propName] != typeof object2[propName]) {
                //Different types => not equal
                return false;
            }
        }
        //Now a deeper check using other objects property names
        for (propName in object2) {
            //We must check instances anyway, there may be a property that only exists in object2
            //I wonder, if remembering the checked values from the first loop would be faster or not
            if (me.hasOwnProperty(propName) != object2.hasOwnProperty(propName)) {
                return false;
            } else if (typeof me[propName] != typeof object2[propName]) {
                return false;
            }
            //If the property is inherited, do not check any more (it must be equa if both objects inherit it)
            if (!me.hasOwnProperty(propName))
                continue;

            //Now the detail check and recursion

            //This returns the script back to the array comparing
            /**REQUIRES Array.equals**/
            if (me[propName] instanceof Array && object2[propName] instanceof Array) {
                // recurse into the nested arrays
                if (!me[propName].equals(object2[propName]))
                    return false;
            } else if (me[propName] instanceof Object && object2[propName] instanceof Object) {
                // recurse into another objects
                //console.log("Recursing to compare ", this[propName],"with",object2[propName], " both named \""+propName+"\"");
                if (!me[propName].equals(object2[propName]))
                    return false;
            }
            //Normal value comparison for strings and numbers
            else if (me[propName] != object2[propName]) {
                return false;
            }
        }
        //If everything passed, let's say YES
        return true;
    }
}

function count(o) {
    var t = typeof o;
    if (t == 'string') {
        return o.length;
    } else if (t == 'object') {
        var n = 0;
        for (var i in o) {
            n++;
        }
        return n;
    }
    return false;
}
$(document).ready(function() {
    $('.clear-element').remove();
});

function dateFormat(fmt, date) {
        let ret;
        const opt = {
            "Y+": date.getFullYear().toString(),        // 年
            "m+": (date.getMonth() + 1).toString(),     // 月
            "d+": date.getDate().toString(),            // 日
            "H+": date.getHours().toString(),           // 时
            "M+": date.getMinutes().toString(),         // 分
            "S+": date.getSeconds().toString()          // 秒
            // 有其他格式化字符需求可以继续添加，必须转化成字符串
        }
        for (let k in opt) {
            ret = new RegExp("(" + k + ")").exec(fmt);
            if (ret) {
                fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
            }
        }
        return fmt;
};

function setMomentToCN(){
	 // 里面的字符可以根据自己的需要进行调整
	 if(typeof moment != 'undefined' && typeof moment.locale != 'undefined')
		return moment.locale('zh-cn', {
            months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_'),
            monthsShort: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
            weekdays: '星期日_星期一_星期二_星期三_星期四_星期五_星期六'.split('_'),
            weekdaysShort: '周日_周一_周二_周三_周四_周五_周六'.split('_'),
            weekdaysMin: '日_一_二_三_四_五_六'.split('_'),
            longDateFormat: {
                LT: 'HH:mm',
                LTS: 'HH:mm:ss',
                L: 'YYYY-MM-DD',
                LL: 'YYYY年MM月DD日',
                LLL: 'YYYY年MM月DD日Ah点mm分',
                LLLL: 'YYYY年MM月DD日ddddAh点mm分',
                l: 'YYYY-M-D',
                ll: 'YYYY年M月D日',
                lll: 'YYYY年M月D日 HH:mm',
                llll: 'YYYY年M月D日dddd HH:mm'
            },
            meridiemParse: /凌晨|早上|上午|中午|下午|晚上/,
            meridiemHour: function (hour, meridiem) {
                if (hour === 12) {
                    hour = 0;
                }
                if (meridiem === '凌晨' || meridiem === '早上' ||
                    meridiem === '上午') {
                    return hour;
                } else if (meridiem === '下午' || meridiem === '晚上') {
                    return hour + 12;
                } else {
                    // '中午'
                    return hour >= 11 ? hour : hour + 12;
                }
            },
            meridiem: function (hour, minute, isLower) {
                const hm = hour * 100 + minute;
                if (hm < 600) {
                    return '凌晨';
                } else if (hm < 900) {
                    return '早上';
                } else if (hm < 1130) {
                    return '上午';
                } else if (hm < 1230) {
                    return '中午';
                } else if (hm < 1800) {
                    return '下午';
                } else {
                    return '晚上';
                }
            },
            calendar: {
                sameDay: '[今天]LT',
                nextDay: '[明天]LT',
                nextWeek: '[下]ddddLT',
                lastDay: '[昨天]LT',
                lastWeek: '[上]ddddLT',
                sameElse: 'L'
            },
            dayOfMonthOrdinalParse: /\d{1,2}(日|月|周)/,
            ordinal: function (number, period) {
                switch (period) {
                    case 'd':
                    case 'D':
                    case 'DDD':
                        return number + '日';
                    case 'M':
                        return number + '月';
                    case 'w':
                    case 'W':
                        return number + '周';
                    default:
                        return number;
                }
            },
            relativeTime: {
                future: '%s内',
                past: '%s前',
                s: '几秒',
                ss: '%d秒',
                m: '1分钟',
                mm: '%d分钟',
                h: '1小时',
                hh: '%d小时',
                d: '1天',
                dd: '%d天',
                M: '1个月',
                MM: '%d个月',
                y: '1年',
                yy: '%d年'
            },
            week: {
                // GB/T 7408-1994《数据元和交换格式·信息交换·日期和时间表示法》与ISO 8601:1988等效
                dow: 1, // Monday is the first day of the week.
                doy: 4  // The week that contains Jan 4th is the first week of the year.
            }
        });
	return false;
};

function selectPostFlag(eveObj,seletVal,inputCtr){
    if(typeof eveObj == 'undefined' || typeof seletVal == 'undefined' || typeof inputCtr == 'undefined' ||
    !eveObj || !inputCtr){
        return false;
    }
    var InputCtrHander = $('#'+inputCtr);
    InputCtrHander.val(seletVal);
    var prevbuttonHander = InputCtrHander.prev('button');
    if(seletVal != '')
        prevbuttonHander.text($(eveObj).text());
    else
        prevbuttonHander.text(prevbuttonHander.attr('title'));
    return true;
};

function autopickupkeyword(eleid,pickupcfg){
    if(!eleid || xn.empty(pickupcfg) || pickupcfg.enable==0){
        $.alert('缺失自动提取关键词的配置信息,或者该版本没有开启此项功能,无法执行自动提取。请手动指定一个或多个关键词，用常见分隔符分隔。',8,{"title":"请完善配置"});
        return false;
    }
}





